<?php
/**
 * This is the template for generating a controller class file.
 */

use yii\helpers\Inflector;
use yii\helpers\StringHelper;

/** @var yii\web\View $this */
/** @var \console\gii\controller\Generator $generator */
$actionVerbs = [
    'index' => "['GET']",
    'create' => "['GET', 'POST']",
    'update' => "['GET', 'POST']",
    'delete' => "['POST']",
    'sort' => "['POST']",
    '__default' => "['GET', 'POST']",
];
$actionIDs = $generator->getActionIDs();
$controllerName = StringHelper::basename($generator->controllerClass);

echo "<?php\n";
?>
/**
 * @link https://www.kancloud.cn/cleverstone/ymb2
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

namespace <?= $generator->getControllerNamespace() ?>;

use <?= trim($generator->baseClass, '\\') ?>;
use builder\helper\App;
use builder\helper\T;
use builder\table\TableBuilder;
use builder\form\FormBuilder;
use <?= trim($generator->modelClass, '\\') ?>;

class <?= $controllerName ?> extends <?= StringHelper::basename($generator->baseClass) . "\n" ?>
{
    /**
     * {@inheritdoc}
     */
    public $actionVerbs = [
<?php foreach ($actionIDs as $action): ?>
        '<?= $action ?>' => <?= isset($actionVerbs[$action]) ? $actionVerbs[$action] : $actionVerbs['__default']  ?>,
<?php endforeach; ?>
    ];

<?php foreach ($actionIDs as $action): ?>
<?php $actionCamelID = Inflector::id2camel($action); ?>
<?php switch ($action): ?>
<?php case 'index': //视图列表 ?>
    /**
     * <?= $generator->sourceName ?>列表
     * @return string
     * @throws \Throwable
     */
    public function action<?= $actionCamelID ?>()
    {
<?= $generator->render('action-index.php', ['actionCamelID' => $actionCamelID]) ?>
    }

<?php break; case 'create': //新增 ?>
    /**
     * 新增<?= $generator->sourceName . "\n" ?>
     * @return string|\yii\web\Response
     * @throws \Throwable
     */
    public function action<?= $actionCamelID ?>()
    {
<?= $generator->render('action-create.php', ['actionCamelID' => $actionCamelID]) ?>
    }

<?php break; case 'update': //更新 ?>
    /**
     * 编辑<?= $generator->sourceName . "\n" ?>
     * @param int $id <?= $generator->sourceName ?>ID
     * @return string|\yii\web\Response
     * @throws \Throwable
     */
    public function action<?= $actionCamelID ?>($id)
    {
<?= $generator->render('action-update.php', ['actionCamelID' => $actionCamelID]) ?>
    }

<?php break; case 'delete': //删除 ?>
    /**
     * 删除<?= $generator->sourceName . "\n" ?>
     * @return \yii\web\Response
     * @throws \Throwable
     */
    public function action<?= $actionCamelID ?>()
    {
<?= $generator->render('action-delete.php', ['actionCamelID' => $actionCamelID]) ?>
    }

<?php break; case 'sort': //排序 ?>
    /**
     * <?= $generator->sourceName ?>列表排序
     * @return \yii\web\Response
     * @throws \Throwable
     */
    public function action<?= $actionCamelID ?>($id)
    {
<?= $generator->render('action-sort.php', ['actionCamelID' => $actionCamelID]) ?>
    }

<?php break; default: ?>
    /**
     * @return string|\yii\web\Response
     * @throws \Throwable
     */
    public function action<?= $actionCamelID ?>()
    {
    }

<?php endswitch; ?>
<?php endforeach; ?>
}
